package com.zhixing.web.api.dataobject.untils;

import com.zhixing.web.api.dataobject.vo.ResultVO;
import com.zhixing.web.common.utils.DateUtil;

import java.util.Map;

/**
 * @author dzh
 * @version 1.0.0.05020
 * <p>project: d-blog</p>
 * <p>created time: 2022/05/02 15:17</p>
 * <p>describe: 返回值工具类</p>
 * <p>remarks: </p>
 **/
public class ResultVoUtil {


    public static ResultVO success(Object object) {

        ResultVO resultVO = new ResultVO();

        // noinspection unchecked
        resultVO.setData(object);

        resultVO.setCode(0);

        resultVO.setMsg("成功");

        resultVO.setTime(DateUtil.getCurrentTime());

        return resultVO;
    }

    public static ResultVO success(Object object, Map<String, Object> params) {

        ResultVO resultVO = new ResultVO();

        // noinspection unchecked
        resultVO.setData(object);

        resultVO.setOtherData(params);

        resultVO.setCode(0);

        resultVO.setMsg("成功");

        resultVO.setTime(DateUtil.getCurrentTime());

        return resultVO;
    }

    public static ResultVO success() {

        return success(null);
    }

    public static ResultVO error(Integer code, String msg) {

        ResultVO resultVO = new ResultVO();

        resultVO.setCode(code);

        resultVO.setMsg(msg);

        resultVO.setTime(DateUtil.getCurrentTime());

        return resultVO;
    }

}
